<?php
class Apps_View_Helper_Snippet extends Zend_View_Helper_Abstract {
    public function snippet($text, $length= 48, $tail="...") {
        $text = trim($text);
        $txtl = strlen($text);
        if($txtl > $length) {
            for($i = 1; $text[$length - $i] != " "; $i++) {
                if($i == $length) {
                    return substr($text, 0, $length) . $tail;
                }
            }
            $text = substr($text, 0, $length-$i+1) . $tail;
        }
        return $text;
    }
}
